/*
 * protocol.h
 *
 *  Created on: Jun 7, 2012
 *      Author: esl32
 */

#ifndef PROTOCOL_H_
#define PROTOCOL_H_

#include <stdio.h>
#include <string.h>
#include <fcntl.h>

#define START 0
#define FRAMEDLE 1
#define DATA 2
#define DATADLE 3

#define DLE 0x10
#define ETX 0x03

#define PARSING 0
#define READY 1
#define MALFORMED 2
#define CHECKSUM_INCORRECT 3

#define RESET 0x40
#define SET_VERTICAL 0x50
#define SET_HORIZONTAL 0x51
#define GET_POSITION 0x60

typedef struct _SerialConn
{
   int fd;
   unsigned char txBuffer[20];
   unsigned char rxBuffer[1];
   unsigned char packetBuffer[20];
   int length;
   int state;
   char checksum;
} SerialConn ;

//int open_conn(char* location, SerialConn* conn);

int parse_next(SerialConn* conn, unsigned char next);

void write_packet(int fd, unsigned char* msg, int length);

#endif /* PROTOCOL_H_ */
